import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/wms/purchase/supplier';

export interface PurchaseSupplierResponse {
    id?: number;
    supplierName: string;
    companyName?: string;
    companyAddress: string;
    contactor?: string;
    contactPhoneNumber?: string;
    accountPeriod?: number;
    bankName?: string;
    bankAccount?: string;
    accountHolder?: string;
    invoiceTitle?: string;
    taxpayerId?: string;
    businessScope?: string;
    supplierComment?: string;
    enterpriseQualification?: string;
    cooperateContract?: string;
    priceContract?: string;
    purchaseContract?: string;

    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

// 管理员添加命令
export interface PurchaseSupplierSaveCommand {
    id?: number;
    supplierName: string;
    companyName?: string;
    companyAddress: string;
    contactor?: string;
    contactPhoneNumber?: string;
    accountPeriod?: number;
    bankName?: string;
    bankAccount?: string;
    accountHolder?: string;
    invoiceTitle?: string;
    taxpayerId?: string;
    businessScope?: string;
    supplierComment?: string;
    enterpriseQualification?: string;
    cooperateContract?: string;
    priceContract?: string;
    purchaseContract?: string;

}

export interface PurchaseSupplierParam {
    supplierName?: string;
    accountPeriod?: number;
    startCreatedAt?: string;
    endCreatedAt?: string;
    page?: number,
    size?:number,
    sort?:Array<string>;
}

export interface PurchaseSupplierResponseList {
    list: PurchaseSupplierResponse[];
    total: number;
}

// 通过id获取管理员详情信息
export function getPurchaseSupplier(id: number) {
    return axios.get<PurchaseSupplierResponse>(`${BASE_URL}/${id}`);
}

// 通过PurchaseSupplierParam参数获取分页列表
export function pagePurchaseSupplier(params: PurchaseSupplierParam) {
    return axios.get<PurchaseSupplierResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 添加管理员
export function addPurchaseSupplier(params: PurchaseSupplierSaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新管理员
export function updatePurchaseSupplier(params: PurchaseSupplierSaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}


// 批量删除管理员
export function deletePurchaseSupplier(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}